<?php

class NginxPoolcontroller extends CController
{
    public function actionProcessMessage()
    {
        if (Yii::app()->request->isAjaxRequest) {
            $channel_id = 12345;

            $c = curl_init( 'http://websockets-test.local/publish?cid=' . $channel_id );
            curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($c, CURLOPT_POST, true);
            curl_setopt($c, CURLOPT_POSTFIELDS, json_encode('<p>>> ' . date('H:i') . ' ' . $_POST['message'] . '</p>'));
            $r = curl_exec($c);

            header('Content-type: application/json');
            echo CJSON::encode(array('status' => 'ok'));
        } else {
            Yii::app()->end();
        }
    }
}
